import Vue from 'vue'
import Vuex from 'vuex'
import count from './modules/count'

Vue.use(Vuex)

const store = new Vuex.Store({
  state: {
    sum: 0,
    status: {
      'success': 'wanmei',
      'error': 'zaogao'
    }
  },
  mutations: {
    addM(state) {
      // 变更状态
      state.sum++
    },
    addMN(state, step) {
      // 变更状态
      state.sum += step
    },
    addMNN(state, step1, step2) {
      // 变更状态
      state.sum += (step1 + step2)
    },
    delM(state) {
      // 变更状态
      state.sum--
    },
    delMN(state, step) {
      // 变更状态
      state.sum -= step
    },
  },
  actions: {
    timeAdd(context, step) {
      setTimeout(() => {
        context.commit('addMN', step)
      }, 2000)
    },
    delMNTime(context, step) {
      setTimeout(() => {
        context.commit('delMN', step)
      }, 2000)
    }
  },
  getters: {
    getSum(state) {
      return '渣渣:' + state.sum
    },
    getCount: state => state.count.myCount,
    allCount: state => state.count.allCount
  },
  modules: {
    count
  }
})

export default store
